
`timescale 1ns/1ps

module Test_pattern	#(parameter 	IMAGE_X = 1920,
												IMAGE_Y = 1080,
												
												DATAWIDTH = 8
												)
(
	input										clk,
	input										rst_n,
	
	input										data_req,
	input										mode_valid,
	input[3:0]								mode,
	
	output	reg[DATAWIDTH-1	:	0]	Rout,
	output	reg[DATAWIDTH-1	:	0]	Gout,
	output	reg[DATAWIDTH-1	:	0]	Bout
	);
	
localparam	PATTERN_WIDTH_X	=	IMAGE_X/8;
localparam	PATTERN_WIDTH_Y	=	IMAGE_Y/8;	
	
reg[12:0]	xcnt,ycnt;
reg[3:0]		modebuf;
reg[31:0]	timecnt;
reg[1:0]			time1ms;

always@(posedge clk or negedge rst_n)
begin
if(~rst_n)
	timecnt <= 0;
else if(timecnt[27])
	timecnt <= 0;
else
	timecnt <= timecnt + 1;
end

always@(posedge clk or negedge rst_n)
begin
if(~rst_n)
	time1ms <= 1'b0;
else if(timecnt[27])
	time1ms <= time1ms + 1'b1;
end

always@(posedge clk or negedge rst_n)
begin
if(~rst_n)
	modebuf	<=	4'd0;
else if(mode_valid)
	modebuf 	<=	mode;
end

	
always@(posedge clk or negedge rst_n)
begin
if(~rst_n)
	xcnt <=	13'd0;
else if(data_req)
	begin
	if(xcnt==IMAGE_X-1)
		xcnt <= 13'd0;
	else
		xcnt <= xcnt + 13'd1;
	end
end

always@(posedge clk or negedge rst_n)
begin
if(~rst_n)
	ycnt <= 13'd0;
else if(data_req)
	begin
	if(xcnt==IMAGE_X-1)
		begin
		if(ycnt==IMAGE_Y-1)
			ycnt <= 13'd0;
		else
			ycnt <= ycnt + 13'd1;
		end
	end
end

always@(posedge clk or negedge rst_n)
begin
if(~rst_n)
	begin
	Rout 	<= 0;
	Gout	<=	0;
	Bout	<=	0;
	end
else if(modebuf==4'd0)
	begin
	if(xcnt<PATTERN_WIDTH_X-1)																			//red 
		begin
		Rout	<=	8'hFF;
		Gout	<=	8'hFF;
		Bout	<=	8'hFF;
		
		end
	else if(xcnt>=PATTERN_WIDTH_X-1 && xcnt<2*PATTERN_WIDTH_X-1)							//carmine 
		begin
		Rout 	<= 8'hFF;
		Gout	<=	8'hFF;
		Bout	<=	8'h00;
		end
	else if(xcnt>=2*PATTERN_WIDTH_X-1 && xcnt<3*PATTERN_WIDTH_X-1)						//Yellow
		begin
		Rout	<=	8'h00;
		Gout	<=	8'hFF;
		Bout	<=	8'hFF;
		end
	else if(xcnt>=3*PATTERN_WIDTH_X-1 && xcnt<4*PATTERN_WIDTH_X-1)						//Gree 						
		begin
		Rout 	<= 8'h00;
		Gout	<=	8'hFF;
		Bout	<=	8'h00;
		end
	else if(xcnt>=4*PATTERN_WIDTH_X-1 && xcnt<5*PATTERN_WIDTH_X-1)						//cyan
		begin
		Rout	<=	8'hFF;
		Gout	<=	8'h00;
		Bout	<=	8'hFF;
		end
	else if(xcnt>=5*PATTERN_WIDTH_X-1 && xcnt<6*PATTERN_WIDTH_X-1)             //Blue
		begin
		Rout	<=	8'hFF;
		Gout	<=	8'h00;
		Bout	<=	8'h00;
		end
	else if(xcnt>=6*PATTERN_WIDTH_X-1 && xcnt<7*PATTERN_WIDTH_X-1)
		begin
		Rout	<=	8'h00;
		Gout	<=	8'h00;
		Bout	<=	8'hFF;
		end
	else if(xcnt>=7*PATTERN_WIDTH_X-1 )
		begin
		Rout	<=	8'hFF;
		Gout	<=	8'hFF;
		Bout	<=	8'hFF;
		end
	end
else if(modebuf==4'd1)
	begin
	if(xcnt<PATTERN_WIDTH_X-1)																			//red 
		begin
		Rout	<=	8'h00;
		Gout	<=	8'h00;
		Bout	<=	8'h00;
		
		end
	else if(xcnt>=PATTERN_WIDTH_X-1 && xcnt<2*PATTERN_WIDTH_X-1)							//carmine 
		begin
		Rout 	<= 8'hFF;
		Gout	<=	8'hFF;
		Bout	<=	8'h00;
		end
	else if(xcnt>=2*PATTERN_WIDTH_X-1 && xcnt<3*PATTERN_WIDTH_X-1)						//Yellow
		begin
		Rout	<=	8'h00;
		Gout	<=	8'hFF;
		Bout	<=	8'h00;
		end
	else if(xcnt>=3*PATTERN_WIDTH_X-1 && xcnt<4*PATTERN_WIDTH_X-1)						//Gree 						
		begin
		Rout 	<= 8'h00;
		Gout	<=	8'hFF;
		Bout	<=	8'hFF;
		end
	else if(xcnt>=4*PATTERN_WIDTH_X-1 && xcnt<5*PATTERN_WIDTH_X-1)						//cyan
		begin
		Rout	<=	8'h00;
		Gout	<=	8'hFF;
		Bout	<=	8'h00;
		end
	else if(xcnt>=5*PATTERN_WIDTH_X-1 && xcnt<6*PATTERN_WIDTH_X-1)             //Blue
		begin
		Rout	<=	8'hFF;
		Gout	<=	8'h00;
		Bout	<=	8'hFF;
		end
	else if(xcnt>=6*PATTERN_WIDTH_X-1 && xcnt<7*PATTERN_WIDTH_X-1)
		begin
		Rout	<=	8'hFF;
		Gout	<=	8'h00;
		Bout	<=	8'h00;
		end
	else if(xcnt>=7*PATTERN_WIDTH_X-1 )
		begin
		Rout	<=	8'hFF;
		Gout	<=	8'hFF;
		Bout	<=	8'hFF;
		end
	end
else if(modebuf==4'd2)
	begin
	Rout	<=	8'h00;
	Gout	<=	8'hFF;
	Bout	<=	8'h00;
	end
else if(modebuf==4'd3)
	begin
	Rout	<=	8'h00;
	Gout	<=	8'h00;
	Bout	<=	8'hFF;
	end
else if(modebuf==4'd4)
	begin
	if(xcnt<500)
		begin
		Rout <= 8'hFF;
		Gout <= 8'hff;
		Bout <= 8'hff;
		end
	else
		begin
		Rout <= 8'h00;
		Gout <= 8'h00;
		Bout <= 8'h00;
		end
	end
else if(modebuf==4'd5)
	begin
	if(xcnt[7]==1)
		begin
		Rout <= 8'hFF;
		Gout <= 8'hFF;
		Bout <= 8'hFF;
		end
	else
		begin
		Rout <= 0;
		Gout <= 0;
		Bout <= 0;
		end
	end

end

endmodule
	
	
	

							